package com.chaoyong.higo.activity;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.entity.StringEntity;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.InputType;
import android.text.TextUtils;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.chaoyong.higo.R;
import com.chaoyong.higo.adapter.SettlementAdapter;
import com.chaoyong.higo.bean.DemoBean;
import com.chaoyong.higo.cainiaowo.CartAdapter;
import com.chaoyong.higo.cainiaowo.CartProvider;
import com.chaoyong.higo.cainiaowo.ShoppingCart;
import com.chaoyong.higo.fragment.FragShoppingBar2;
import com.chaoyong.higo.net.OApi;
import com.chaoyong.higo.utils.JLog;
import com.chaoyong.higo.utils.PrefUtils;
import com.chaoyong.higo.utils.Values;
import com.chaoyong.higo.view.XListView;
import com.fanwei.sdk.activity.HandlerCallback;
import com.fanwei.sdk.api.PaySdk;
import com.fanwei.sdk.bean.PayParam;
import com.google.gson.Gson;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;

public class PayActivity extends Activity implements OnClickListener {

	private Activity context;
	private XListView xlv;
	private TextView tv_money,tv_pay_money;
	private LinearLayout ll_fufen,ll_yue;
	private ImageView iv_fufen,iv_yue;
	private RadioButton rb_hc,rb_wx;
	private SettlementAdapter adapter;
	private List<DemoBean.DataEntity> data;
	private Button btn_pay;
	private int num;
	
	private ArrayList<ShoppingCart> datas;
	
	private TextView tv_yunbi,tv_yue,tv_yunbi1,tv_yue1;
	private String yue,yunbi;
	
	private CartAdapter cartAdapter;
	
	
	private List<ShoppingCart> carts;
	private CartProvider cartProvider;
	//private String uid = PrefUtils.getString(context, "userId", "");
	
	private AlertDialog.Builder zf_dialog;
	
	private LinearLayout back;
	
	private boolean byb = false;
	private boolean bye = false;
	
	private RadioGroup pay_rg;
	
	//private FragShoppingBar2 fsb = new FragShoppingBar2(null);
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_pay);
		this.context = this;
		initViews();
		
	}

	private void initViews() {
		back = (LinearLayout) findViewById(R.id.back_btn);
		back.setOnClickListener(this);
		
		xlv = (XListView) findViewById(R.id.xlv_pay);
		
		tv_money = (TextView) findViewById(R.id.pay_money);
		tv_pay_money = (TextView) findViewById(R.id.pay_pay_money);
		
		ll_fufen = (LinearLayout) findViewById(R.id.pay_ll_fufen);
		ll_yue = (LinearLayout) findViewById(R.id.pay_ll_yue);
		
		iv_fufen = (ImageView) findViewById(R.id.pay_iv_fufen);
		iv_yue = (ImageView) findViewById(R.id.pay_iv_yue);
		
		rb_hc = (RadioButton) findViewById(R.id.pay_type_hc);
		rb_wx = (RadioButton) findViewById(R.id.pay_type_wx);
		
		tv_yunbi = (TextView) findViewById(R.id.pay_yunbi);
		tv_yue = (TextView) findViewById(R.id.pay_yue);
		
		tv_yunbi1 = (TextView) findViewById(R.id.pay_yunbi1);
		tv_yue1 = (TextView) findViewById(R.id.pay_yue1);
		
		yue = PrefUtils.getString(context, "yue", "0");
		yunbi = PrefUtils.getString(context, "yunbi", "0");
		tv_yunbi.setText("（您的云币：" + yunbi + "）");
		tv_yue.setText("（您的余额：￥" + yue + "）");
		
		adapter = new SettlementAdapter(context);
		xlv.setAdapter(adapter);
		
		xlv.setPullLoadEnable(false);
		xlv.setPullRefreshEnable(false);
		xlv.setPullRefreshEnable(false);
		
		btn_pay = (Button) findViewById(R.id.pay_btn_pay);
		btn_pay.setOnClickListener(this);
		
		ll_fufen.setOnClickListener(this);
		ll_yue.setOnClickListener(this);
		
		rb_hc.setOnClickListener(this);
		rb_wx.setOnClickListener(this);
		
		cartProvider = new CartProvider(this);
		carts = cartProvider.getAll();
		
		pay_rg = (RadioGroup) findViewById(R.id.pay_rg);
	}
	
	
	@Override
	protected void onStart() {
		super.onStart();
		/*datas = (ArrayList<ShoppingCart>) getIntent().getSerializableExtra("datas");
		Toast.makeText(context, datas.get(0).getGoods_name(), 0).show();*/
		JSONObject info = null;
		try {
			info = new JSONObject(getIntent().getStringExtra("info"));
		} catch (JSONException e1) {
			e1.printStackTrace();
		}
		
		RequestParams params = new RequestParams();
		try {
			params.setBodyEntity(new StringEntity(info.toString(), "utf-8"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		
		HttpUtils utils = new HttpUtils();
		utils.send(HttpMethod.POST,OApi.Public_appBuy , params, new RequestCallBack<String>() {

			@Override
			public void onFailure(HttpException arg0, String arg1) {
				Toast.makeText(context, arg1, 0).show();
			}

			@Override
			public void onSuccess(ResponseInfo<String> arg0) {
				Gson gson  = new Gson();
				String result = arg0.result;
				try {
					JSONObject json = new JSONObject(result);
					if(json.getInt("status") == 0){
						Toast.makeText(PayActivity.this, json.getString("data"), 0).show();
						finish();
					}
					if(json.getInt("status") == 1){
						DemoBean demoBean = gson.fromJson(result, DemoBean.class);
						if (demoBean.getStatus().equals("1")) {
							data = demoBean.getData();
							num = 0;
							for (int i = 0; i < data.size(); i++) {
								num += data.get(i).getNum();
							}
							tv_money.setText("总需支付金额：￥"+ num);
							tv_pay_money.setText("总需支付金额：￥"+ num);
							adapter.changeDatas(data);
							
							if(Double.parseDouble(yue) < num){
				 				tv_yue1.setText("余额不足");
							}
							if(Double.parseDouble(yunbi) < num){
								tv_yunbi1.setText("云币不足");
							}
						}
					}
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				
			}
		});
		
		
		
		
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.back_btn:
			finish();
			break;
		case R.id.pay_btn_pay:
			if(!rb_hc.isChecked() && !rb_wx.isChecked()  && byb == false && bye == false){
				Toast.makeText(context, "请选择支付方式", 0).show();
				return ;
			}
			
			if(byb){
				//Toast.makeText(context, "云币支付", 0).show();
				/*if(true){
					AlertDialog.Builder builder = new AlertDialog.Builder(context);
					builder.setTitle("请输入支付密码");
					EditText et = new EditText(context);
					et.setBackground(getResources().getDrawable(R.drawable.shape_pay_type_line));
					et.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
					builder.setView(et);
					builder.setNegativeButton("取消", null);
					builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
						
						@Override
						public void onClick(DialogInterface dialog, int which) {
							// TODO Auto-generated method stub
							Toast.makeText(context, "dfad", 0).show();
						}

					});
					builder.create().show();
					return ;
				}*/
				showDialog();
				//yunbiPay();
			}
			
			if(bye){
				//Toast.makeText(context, "余额支付", 0).show();
				showDialog1();
				//yuePay();
			}
			
			if(rb_hc.isChecked()){
				huichaoPay();
			}
			if(rb_wx.isChecked()){
				zhifubaoPay();
			}
			break;
			
		case R.id.pay_ll_fufen:
			if(Integer.parseInt(PrefUtils.getString(context, "yunbi", "0")) < num){
				Toast.makeText(context, "您的云币不足！", 0).show();
				return;
			}
			/*if(Double.parseDouble(PrefUtils.getString(context, "yue", "0")) < num){
				Toast.makeText(context, "您的余额不足！", 0).show();
				return;
			}*/
			iv_fufen.setImageResource(R.drawable.icon_pay_type02);
			iv_yue.setImageResource(R.drawable.icon_pay_type01);
			/*rb_hc.setChecked(false);
			rb_wx.setChecked(false);*/
			pay_rg.clearCheck();
			byb = true;
			bye = false;
			break;
		case R.id.pay_ll_yue:
			/*if(Integer.parseInt(PrefUtils.getString(context, "yunbi", "0")) < num){
				Toast.makeText(context, "您的云币不足！", 0).show();
				return;
			}*/
			if(Double.parseDouble(PrefUtils.getString(context, "yue", "0")) < num){
				Toast.makeText(context, "您的余额不足！", 0).show();
				return;
			}
			iv_fufen.setImageResource(R.drawable.icon_pay_type01);
			iv_yue.setImageResource(R.drawable.icon_pay_type02);
			/*rb_hc.setChecked(false);
			rb_wx.setChecked(false);*/
			pay_rg.clearCheck();
			bye = true;
			byb = false;
			break;
		case R.id.pay_type_hc:
			//rb_hc.setChecked(true);
			iv_fufen.setImageResource(R.drawable.icon_pay_type01);
			iv_yue.setImageResource(R.drawable.icon_pay_type01);
			bye = false;
			byb = false;
			break;
		case R.id.pay_type_wx:
			//rb_wx.setChecked(true);
			iv_fufen.setImageResource(R.drawable.icon_pay_type01);
			iv_yue.setImageResource(R.drawable.icon_pay_type01);
			bye = false;
			byb = false;
			break;
			

		}
	}

	private void jubaoPay() {
		// TODO Auto-generated method stub
		JSONObject json = new JSONObject();
		try {
			json.put("uid",PrefUtils.getString(context, "userId", ""));
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		RequestParams params = new RequestParams();
		try {
			params.setBodyEntity(new StringEntity(json.toString(), "utf-8"));
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		HttpUtils utils = new HttpUtils();
		utils.send(HttpMethod.POST, OApi.jubaoApp, params, new RequestCallBack<String>() {

			@Override
			public void onFailure(HttpException arg0, String arg1) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onSuccess(ResponseInfo<String> arg0) {
				// TODO Auto-generated method stub
				String result = arg0.result;
				try {
					JSONObject js = new JSONObject(result);
					if(js.getInt("status") == 1){
						JSONObject data = js.getJSONObject("data");
						String goodsname = data.getString("goodsname");
						String payid = data.getString("payid");
						String amount = data.getString("amount");
						String playerid = data.getString("playerid");
						
						PayParam payParam = new PayParam();
						payParam.setAmount(amount);
						payParam.setGoodsname(goodsname);
						payParam.setPlayerid(playerid);
						payParam.setPayid(payid);
						
						PaySdk.startPay(context, payParam, new HandlerCallback() {
							
							@Override
							public void processResult(int arg0, String arg1) {
								// TODO Auto-generated method stub
								/*String result = arg0 + arg1;
								Toast.makeText(context, result, 0).show();*/
								/*Toast.makeText(context, "[resultCode=" + arg0 + "][result=" + arg1 + "]",
										Toast.LENGTH_LONG).show();*/
								Toast.makeText(context, arg1, 0).show();
									switch (arg0) {
									case 0:
										
										for (int i = 0; i < carts.size(); i++) {
											cartProvider.delete(carts.get(i));
										}
										MainActivity.badgeView.decrement(Values.idList.size());
										Values.idList.clear();
										Intent in = new Intent(context, PurchaseRecordActivity.class);
										in.putExtra("type", 1);
										startActivity(in);
										context.finish();
										break;
									default:
										break;
									}
							}
						});
						
					}else{
						Toast.makeText(context, "支付遇到问题，请联系客服人员！", 0).show();
					}
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
	}

	private void showDialog() {
		// TODO Auto-generated method stub
		zf_dialog = new AlertDialog.Builder(context);
		zf_dialog.setTitle("请输入支付密码");
		final EditText et = new EditText(context);
		et.setTransformationMethod(PasswordTransformationMethod.getInstance());
		et.setBackgroundResource(R.drawable.shape_pay_editext_zhifu);
		//LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);;
		
		zf_dialog.setView(et);
		
		zf_dialog.setCancelable(false);
		zf_dialog.setPositiveButton("确定", new Dialog.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
				if(TextUtils.isEmpty(et.getText().toString())){
					Toast.makeText(context, "请输入支付密码！", 0).show();
					return ;
				}
				verificationZfpwd(et.getText().toString());
			}
		});
		zf_dialog.setNegativeButton("取消", null);
		zf_dialog.create().show();
	}
	
	private void showDialog1() {
		// TODO Auto-generated method stub
		zf_dialog = new AlertDialog.Builder(context);
		zf_dialog.setTitle("请输入支付密码");
		final EditText et = new EditText(context);
		//MainActivity.this.passwd.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
		et.setTransformationMethod(PasswordTransformationMethod.getInstance());
		et.setBackgroundResource(R.drawable.shape_pay_editext_zhifu);
		//LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);;
		
		zf_dialog.setView(et);
		
		zf_dialog.setCancelable(false);
		zf_dialog.setPositiveButton("确定", new Dialog.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
				if(TextUtils.isEmpty(et.getText().toString())){
					Toast.makeText(context, "请输入支付密码！", 0).show();
					return ;
				}
				verificationZfpwd1(et.getText().toString());
			}
		});
		zf_dialog.setNegativeButton("取消", null);
		zf_dialog.create().show();
	}

	protected void verificationZfpwd(String string) {
		// TODO Auto-generated method stub
		JSONObject json = new JSONObject();
		try {
			json.put("uid",PrefUtils.getString(context, "userId", ""));
			json.put("password", string);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		RequestParams params = new RequestParams();
		try {
			params.setBodyEntity(new StringEntity(json.toString(), "utf-8"));
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		HttpUtils utils = new HttpUtils();
		utils.send(HttpMethod.POST, OApi.Appport_checkPay, params, new RequestCallBack<String>() {

			@Override
			public void onFailure(HttpException arg0, String arg1) {
				// TODO Auto-generated method stub
				Toast.makeText(context, arg1, 0).show();
			}

			@Override
			public void onSuccess(ResponseInfo<String> arg0) {
				// TODO Auto-generated method stub
				String result = arg0.result;
				try {
					JSONObject jso = new JSONObject(result);
					if(jso.getInt("status") == 1){
						yunbiPay();
					}else{
						Toast.makeText(context, "支付密码不正确", 0).show();
						return ;
					}
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
	}
	
	protected void verificationZfpwd1(String string) {
		// TODO Auto-generated method stub
		JSONObject json = new JSONObject();
		try {
			json.put("uid",PrefUtils.getString(context, "userId", ""));
			json.put("password", string);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		RequestParams params = new RequestParams();
		try {
			params.setBodyEntity(new StringEntity(json.toString(), "utf-8"));
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		HttpUtils utils = new HttpUtils();
		utils.send(HttpMethod.POST, OApi.Appport_checkPay, params, new RequestCallBack<String>() {

			@Override
			public void onFailure(HttpException arg0, String arg1) {
				// TODO Auto-generated method stub
				Toast.makeText(context, arg1, 0).show();
			}

			@Override
			public void onSuccess(ResponseInfo<String> arg0) {
				// TODO Auto-generated method stub
				String result = arg0.result;
				try {
					JSONObject jso = new JSONObject(result);
					if(jso.getInt("status") == 1){
						yuePay();
					}else{
						Toast.makeText(context, "支付密码不正确", 0).show();
						return ;
					}
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
	}

	private void zhifubaoPay() {
		//Toast.makeText(context, "WePay!", 0).show();
		jubaoPay();
	}

	
	private void huichaoPay() {
		String uid = PrefUtils.getString(context, "userId", "");
		RequestParams params = new RequestParams();
		try {
			JSONObject o = new JSONObject();
			JSONObject info = new JSONObject();
			o.put("model", "GoodsRecord");
			o.put("function", "PayApp");
			o.put("info", info);
			info.put("pay_type", "hcWap");
			info.put("uid", uid);
			params.setBodyEntity(new StringEntity(o.toString(), "utf-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		HttpUtils utils = new HttpUtils();
		utils.send(HttpMethod.POST, OApi.appport_PayApp, params, new RequestCallBack<String>() {

			@Override
			public void onFailure(HttpException arg0, String arg1) {
				Toast.makeText(context, arg1, 0).show();
			}

			@Override
			public void onSuccess(ResponseInfo<String> arg0) {
				String result = arg0.result;
				try {
					JSONObject hcjs = new JSONObject(result);
					String url = hcjs.getString("data");
					//Toast.makeText(context, url, 0).show();
					Intent intent = new Intent(context, HuichaoPayActivity.class);
					intent.putExtra("url", url);
					startActivity(intent);
					overridePendingTransition(R.anim.slide_in_from_bottom, R.anim.slide_out_to_bottom);
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
	}
	
	private void yuePay() {
		String uid = PrefUtils.getString(context, "userId", "");
		RequestParams params = new RequestParams();
		try {
			JSONObject o = new JSONObject();
			JSONObject info = new JSONObject();
			o.put("model", "GoodsRecord");
			o.put("function", "PayApp");
			o.put("info", info);
			info.put("balance", "on");
			info.put("uid", uid);
			params.setBodyEntity(new StringEntity(o.toString(), "utf-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		HttpUtils utils = new HttpUtils();
		utils.send(HttpMethod.POST, OApi.appport_PayApp, params, new RequestCallBack<String>() {

			@Override
			public void onFailure(HttpException arg0, String arg1) {
				Toast.makeText(context, arg1, 0).show();
			}

			@Override
			public void onSuccess(ResponseInfo<String> arg0) {
				String result = arg0.result;
				try {
					JSONObject json = new JSONObject(result);
					//Toast.makeText(context, json.getString("data"), 0).show();
					if(json.getInt("status") == 1){
						//cartAdapter = new CartAdapter(context, null, null, null, null);
						//cartAdapter.delAllCart();
						Toast.makeText(context, "支付成功", 0).show();
						for (int i = 0; i < carts.size(); i++) {
							cartProvider.delete(carts.get(i));
						}
						MainActivity.badgeView.decrement(Values.idList.size());
						Values.idList.clear();
						Intent intentGo = new Intent(context, PurchaseRecordActivity.class);
						intentGo.putExtra("type", 1);
						startActivity(intentGo);
						PayActivity.this.finish();
					}
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				//JLog.i("pay", result);
			}
		});
	}
	
	
	private void yunbiPay() {
		String uid = PrefUtils.getString(context, "userId", "");
		RequestParams params = new RequestParams();
		try {
			JSONObject o = new JSONObject();
			JSONObject info = new JSONObject();
			o.put("model", "GoodsRecord");
			o.put("function", "PayApp");
			o.put("info", info);
			info.put("yunbi", "on");
			info.put("uid", uid);
			params.setBodyEntity(new StringEntity(o.toString(), "utf-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		HttpUtils utils = new HttpUtils();
		utils.send(HttpMethod.POST, OApi.appport_PayApp, params, new RequestCallBack<String>() {

			@Override
			public void onFailure(HttpException arg0, String arg1) {
				Toast.makeText(context, arg1, 0).show();
			}

			@Override
			public void onSuccess(ResponseInfo<String> arg0) {
				String result = arg0.result;
				try {
					JSONObject json = new JSONObject(result);
					//Toast.makeText(context, json.getString("data"), 0).show();
					if(json.getInt("status") == 1){
						//cartAdapter = new CartAdapter(context, null, null, null, null);
						//cartAdapter.delAllCart();
						//fsb.delAllCart();
						//startActivity(new Intent(PayActivity.this, MainActivity.class));
						/*datas.clear();
						setResult(0);*/
						// delete gouwuche
						
						Toast.makeText(context, "支付成功", 0).show();
						for (int i = 0; i < carts.size(); i++) {
							cartProvider.delete(carts.get(i));
						}
						MainActivity.badgeView.decrement(Values.idList.size());
						Values.idList.clear();
						Intent intent1 = new Intent(context, PurchaseRecordActivity.class);
						intent1.putExtra("type", 1);
						startActivity(intent1);
						PayActivity.this.finish();
					}
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
	}
	
	
	private void httpCommitPayBalance() {
		String uid = PrefUtils.getString(context, "userId", "");
		HttpUtils util = new HttpUtils();
		RequestParams params = new RequestParams();
		try {
			JSONObject o = new JSONObject();
			JSONObject info = new JSONObject();
			o.put("model", "GoodsRecord");
			o.put("function", "PayApp");
			o.put("info", info);
			info.put("balance", "on");
//			info.put("uid", uid);
			params.setBodyEntity(new StringEntity(o.toString(), "UTF-8"));
		} catch (Exception e) {
		}
		util.send(HttpMethod.POST, OApi.appport_PayApp, params, new RequestCallBack<String>() {

			@Override
			public void onFailure(HttpException arg0, String arg1) {
				Toast.makeText(context, arg1, 0).show();
			}

			@Override
			public void onSuccess(ResponseInfo<String> arg0) {
				try {
					JSONObject o = new JSONObject(arg0.result);
					String data = o.getString("data");
					//Toast.makeText(context, data, 0).show();
					if (o.getString("status").equals("1")) {
						OApi.isPaySuccesss = 1;
						PayActivity.this.finish();
					}
				} catch (JSONException e) {
					e.printStackTrace();
				}
			}
		});
	}
	
	private void httpCommitPayYunbi() {
		String uid = PrefUtils.getString(context, "userId", "");
		HttpUtils util = new HttpUtils();
		RequestParams params = new RequestParams();
		try {
			JSONObject o = new JSONObject();
			JSONObject info = new JSONObject();
			o.put("model", "GoodsRecord");
			o.put("function", "PayApp");
			o.put("info", info);
			info.put("balance", "on");
			info.put("uid", uid);
			params.setBodyEntity(new StringEntity(o.toString(), "UTF-8"));
		} catch (Exception e) {
		}
		util.send(HttpMethod.POST, OApi.appport_PayApp, params, new RequestCallBack<String>() {

			@Override
			public void onFailure(HttpException arg0, String arg1) {
				Toast.makeText(context, arg1, 0).show();
			}

			@Override
			public void onSuccess(ResponseInfo<String> arg0) {
				try {
					JSONObject o = new JSONObject(arg0.result);
					String data = o.getString("data");
					//Toast.makeText(context, data, 0).show();
					if (o.getString("status").equals("1")) {
						OApi.isPaySuccesss = 1;
						PayActivity.this.finish();
					}
				} catch (JSONException e) {
					e.printStackTrace();
				}
			}
		});
	}
	
	
}
